package com.cyufeng.blog.repository;

import com.cyufeng.blog.entity.Images;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * 轮播图
 * @author Cyufeng
 * Data:2018.12.30
 */
@Repository
public interface ImagesRepository extends JpaRepository<Images,Integer> {
    /**
     * 得到所有的图片
     * @return List<Images>
     */
    @Query(value = "select * from image t where t.DR ='0' and t.IS_ENABLE = '1' ",nativeQuery = true)
    List<Images> getImages();

    /**
     * 得到所有的图片--用于后台操作
     * @return List<Images>
     */
    @Query(value = "select * from image t where t.DR ='0' ",nativeQuery = true)
    List<Images> getAllImages();

    /**
     * 更新是否启用字段
     *
     * @return
     */
    @Modifying
    @Query(value = "update image t set IS_ENABLE = ? where t.DR ='0' and t.id =?", nativeQuery = true)
    void setIsEnable(int isEnable, int id);

    /**
     * 删除图片
     *
     * @return
     */
    @Modifying
    @Query(value = "update image t set t.DR = 1 where t.id =?", nativeQuery = true)
    void deleteImage(int id);
}
